<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Navigation Component</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #4169E1;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }

        .nav-container {
            background: #000000;
            padding: 8px;
            border-radius: 40px;
            display: flex;
            gap: 8px;
            width: fit-content;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .nav-item {
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 30px;
            cursor: pointer;
            color: #000;
            text-decoration: none;
            transition: all 0.3s ease;
            background-color: #FFFFFF;
            /* 未激活状态为圆形 */
            width: 48px;
            height: 48px;
            padding: 12px;
        }

        /* 激活状态样式 */
        .nav-item.active {
            width: auto;
            padding: 12px 24px;
            background-color: #FFD700;
            justify-content: flex-start;
        }

        .nav-icon {
            width: 24px;
            height: 24px;
            min-width: 24px;
            fill: currentColor;
        }

        .nav-text {
            margin-left: 8px;
            font-size: 16px;
            font-weight: 500;
            white-space: nowrap;
            /* 默认隐藏文字 */
            display: none;
        }

        /* 激活状态显示文字 */
        .nav-item.active .nav-text {
            display: block;
        }

        @media (max-width: 600px) {
            .nav-container {
                width: 90%;
                max-width: 300px;
            }
        }
    </style>
</head>
<body>
    <nav class="nav-container">
        <a href="#" class="nav-item">
            <svg class="nav-icon" viewBox="0 0 24 24">
                <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
            </svg>
            <span class="nav-text">Home</span>
        </a>
        
        <a href="#" class="nav-item">
            <svg class="nav-icon" viewBox="0 0 24 24">
                <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
            </svg>
            <span class="nav-text">Search</span>
        </a>
        
        <a href="#" class="nav-item">
            <svg class="nav-icon" viewBox="0 0 24 24">
                <path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z"/>
            </svg>
            <span class="nav-text">Chat</span>
        </a>
        
        <a href="#" class="nav-item active">
            <svg class="nav-icon" viewBox="0 0 24 24">
                <path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/>
            </svg>
            <span class="nav-text">Profile</span>
        </a>
    </nav>

    <script>
        document.querySelectorAll('.nav-item').forEach(item => {
            item.addEventListener('click', (e) => {
                e.preventDefault();
                document.querySelectorAll('.nav-item').forEach(el => {
                    el.classList.remove('active');
                });
                item.classList.add('active');
            });
        });

        // 添加键盘导航支持
        document.addEventListener('keydown', (e) => {
            const activeItem = document.querySelector('.nav-item.active');
            const items = Array.from(document.querySelectorAll('.nav-item'));
            const currentIndex = items.indexOf(activeItem);

            if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
                e.preventDefault();
                const nextIndex = (currentIndex + 1) % items.length;
                items[nextIndex].click();
            } else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
                e.preventDefault();
                const prevIndex = (currentIndex - 1 + items.length) % items.length;
                items[prevIndex].click();
            }
        });
    </script>
</body>
</html>
</html>